    <link rel="stylesheet" media="screen, print"
          href="{{ asset('_third/smart/css/formplugins/select2/select2.bundle.css') }}">
    <style>
        .table {
            border: none;
        }

        .table-hover tbody tr:hover {
            -webkit-box-shadow: none !important;
            box-shadow: none !important;
        }

        .table-hover tbody tr:hover {
            background-color: transparent !important;
        }

        .form_tr {
            padding-right: 0.75rem;
            padding-left: 0.75rem;
            display: flex;
            flex-flow: row nowrap;
            justify-content: space-between;
            align-items: center;
        }

        .content {
            height: 45px;
            box-sizing: border-box;
        }

        .content td {
            height: 100%;
            padding: 0 !important;
            line-height: 45px;
        }

        .table-bordered th td {
            text-align: left;
        }

        .table-bordered tbody td {
            border: 1px solid #e9e9e9;
            text-align: center;
            white-space: nowrap;
        }

        .table-bordered tbody td,
        .table-bordered th td {
            width: calc(100% / 11);
            box-sizing: border-box;
        }

        .title_tr td {
            padding-right: 0;
            padding-left: 0;
            background: #f1f1f1;
        }

        .byqx {
            width: 32.94px;
            height: 25px;
        }

        /*标题图片 */
        .table_img {
            margin-right: 7px;
            margin-bottom: 4px;
        }

        .custom-control {
            top: 10px;
        }

        .custom-control-input:checked~.custom-control-label::before {
            background-color: #4679cc;
            border-color: #007bff;
        }

        .form-group {
            margin-top: 5px;
            margin-left: 2px;
            margin-right: 2px;
        }

        .form_select {
            margin: 2px 2px 0 2px !important;
        }

        .form-control {
            padding: 0;
        }

        .setting {
            margin-right: 0;
            padding: 0.45rem;
            margin-bottom: 5px;
        }

        .table .th_title {
            background: #f1f1f1;
            height: 52px;
            font-size: 15px;
            font-family: Source Han Sans SC-Medium, Source Han Sans SC;
            font-weight: 500;
            color: #333333;
            display: flex;
            flex-flow: row nowrap;
            justify-content: space-between;
            padding: 0;
        }

        .table .th_title .title-text {
            margin: 0.75rem;
            font-weight: bolder;
        }

        .table .th_title .btn {
            margin: 8px;
        }

        .table .sub_title .th_title {
            background: #fff;
            width: 100%;
            border: none;
        }

        .modal-footer,
        .modal-header {
            justify-content: center;
        }

        .modal-header {
            background: #f1f1f1;
        }

        .modal-body {
            padding-top: 1.25rem;
        }

        .isHiden {
            display: none;
        }

        .isShow {
            display: inline-block;
        }

        .row_last_td {
            position: relative;
        }

        .delete_row {
            width: 20px;
            height: 20px;
            border-radius: 50%;
            background: #D9001B;
            position: absolute;
            right: -30px;
            top: 10px;
        }

        .delete_content {
            width: 10px;
            height: 5px;
            background: #fff;
            margin-top: 7.5px;
            margin-left: 5px;
        }

        .module_content {
            padding-right: 20px;
        }

        #add_selef_module {
            margin-right: 28px;
        }
    </style>
    <main id="js-page-content" role="main" class="page-content "
          style="background: linear-gradient(180deg, #F8F6F9 0%, #FAF8FB 100%);">
        <div id="content_box" style="background: #fff;">
            <form id="table_form" novalidate="" method="post">
                <table id="main_table" class="table table-bordered table-hover m-0">
                    <thead class="thead-themed">
                    <tr class="content">
                        <th colspan="12" class="th_title">
                            <div class="title-text">
                                <img src="/web/img/student/byqx.png" class="table_img byqx" /><span>字段设置</span>
                            </div>
                            <button id="add_selef_module" type="button" class="btn btn-primary btn-sm">新增模块</button>
                        </th>
                    </tr>
                    </thead>
                </table>
            </form>
            <!-- 生源信息 -->
            <div class="module_content">

            </div>
        </div>
        <div class="modal fade" id="nameChangeModal" tabindex="-1" role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">提示</h5>
                    </div>
                    <div class="modal-body">
                        <form>
                            <div class="form-group row">
                                <label class="col-sm-2 col-form-label" for="simpleinput">模块名称</label>
                                <input type="text" id="new_module_name"  maxlength="20" class="form-control col-sm-10">
                            </div>
                        </form>
                    </div>
                    <div class="modal-footer" aria-hidden="false">
                        <button onclick="setModuleName()" type="button" class="btn btn-primary">确定</button>
                        <button type="button" class="btn btn-primary" data-dismiss="modal" aria-label="Close">取消</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="modal fade" id="settingModal" tabindex="-1" role="dialog">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title">提示</h5>
                    </div>
                    <div class="modal-body">
                        <form class="custom_type_select">

                        </form>
                    </div>
                    <div class="modal-footer">
                        <button onclick="saveSetSelect()" type="button" class="btn btn-primary">确定</button>
                        <button type="button" class="btn btn-primary" data-dismiss="modal" aria-label="Close">取消</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="text-center mt-2">
            <button id="submit_form" type="button" class="btn btn-primary" onclick="handleSubmit()">确认</button>
            <button type="button" class="btn btn-primary" onclick="window.history.back()">返回</button>
        </div>
    </main>
    <script src="{{URL::asset('_third/smart/js/formplugins/select2/select2.bundle.js')}}"></script>
    <script src="{{URL::asset('admin/js/for_ajax.js')}}"></script>
    <script type='text/javascript'>
        //初始化模块
        var moduleList = [];

        //数据回填
        function delRealData(res) {
            moduleList = res.map(item => {
                let moduleFlag = generateTenDigitRandomNumber()
                let field_data = item.field_data.map(item => {
                    let rowFlag = generateTenDigitRandomNumber()
                    let custom_config=item.custom_config?JSON.parse(item.custom_config):[]
                    console.log(custom_config,'custom_config')
                    return {
                        ...item,
                        rowFlag: rowFlag,
                        //多选或者单选收集字段应该初始化为空数组
                        custom_config
                    }
                })
                return {
                    ...item,
                    key: moduleFlag,
                    // html渲染主体
                    htmlList: getModule(moduleFlag, field_data, item.module_name, item.module_type),
                    field_data,
                }
            })
            initModules()
        }

         console.log(@json($config),'>>>>')
         //数字转中文
         function numberToChinese(num) {
             const units = ['', '十', '百', '千'];
             const nums = ['零', '一', '二', '三', '四', '五', '六', '七', '八', '九'];

             if (num === 0) return nums[0];

             let result = '';
             let strNum = num.toString();
             let len = strNum.length;

             for (let i = 0; i < len; i++) {
                 let digit = parseInt(strNum[i]);
                 let unit = units[len - i - 1];

                 if (digit === 0) {
                     // 避免重复的“零”
                     if (result[result.length - 1] !== nums[0]) {
                         result += nums[digit];
                     }
                 } else {
                     result += nums[digit] + unit;
                 }
             }

             // 处理末尾的“零”
             if (result[result.length - 1] === nums[0]) {
                 result = result.slice(0, -1);
             }

             // 处理“一十”开头的特殊情况
             if (result.startsWith('一十')) {
                 result = result.slice(1);
             }

             return result;
         }
        delRealData(@json($config))
        //模块表头操作
        function delSelfModule(type) {
            let stuModuleFlag = generateTenDigitRandomNumber()
            let stuRowFlag = generateTenDigitRandomNumber()
            let selfModuleFlag = generateTenDigitRandomNumber()
            let selfRowFlag = generateTenDigitRandomNumber()
            switch (type) {
                //删除自定义模块
                case 'del':
                    initModules();
                    break;
                case 'add':
               //自定义模块新增排序
               let length=numberToChinese(moduleList.length-1)
                    //只有自定义模块可以重复新增删除，所以只需要判断第一个模块是否是自定义模块即可
                    if (moduleList[0] && moduleList[0].module_type == 1) {
                        moduleList.push({
                            key: selfModuleFlag,
                            module_name: '自定义模块'+length,
                            module_type: 2,
                            htmlList: getModule(selfModuleFlag, [{
                                rowFlag: selfRowFlag,
                                ...rowDataStruct()
                            }], '自定义模块'+length, 2),
                            field_data: [{
                                rowFlag: selfRowFlag,
                                ...rowDataStruct()
                            }]
                        })
                    } else {
                        moduleList.push({
                            key: stuModuleFlag,
                            module_name: '生源信息',
                            module_type: 1,
                            htmlList: getModule(stuModuleFlag, [{
                                rowFlag: stuRowFlag,
                                ...rowDataStruct()
                            }], '生源信息', 1),
                            field_data: [{
                                rowFlag: stuRowFlag,
                                ...rowDataStruct()
                            }]
                        }, {
                            key: selfModuleFlag,
                            module_name: '自定义模块'+length,
                            module_type: 2,
                            htmlList: getModule(selfModuleFlag, [{
                                rowFlag: selfRowFlag,
                                ...rowDataStruct()
                            }], '自定义模块'+length, 2),
                            field_data: [{
                                rowFlag: selfRowFlag,
                                ...rowDataStruct()
                            }]
                        })
                    }
                    initModules()
                    break;
            }
        }

        //模块初始化
        function initModules() {
            $(".module_content").html('') // 创建之前先清空原有dom
            moduleList.forEach((item, index) => {
        // console.log(item.htmlList, '>>>>')
                $(".module_content").append(item.htmlList)
            })
        }

        //删除某自定义模块
        function deleteSelfModule(e, moduleFlag) {
            const index = moduleList.findIndex(item => item.key == moduleFlag)
            if (moduleList.length == 2 || moduleList.length < 2) {
                showToastr("至少保留一个自定义模块", "提示")
                return
            }
            moduleList.splice(index, 1)
            delSelfModule('del')
        }

        //新增模块
        $('#add_selef_module').click(function() {
            const selfModuleLength = moduleList.filter(item=>item.module_type===2).length
            console.log(moduleList.filter(item=>item.module_type===2),'>>>')
            if (selfModuleLength == 20 || selfModuleLength >20) {
                showToastr("已达到模块上限，不可新增", "提示")
            } else {
                //给生成的模块添加标识
                delSelfModule('add')
            }
        })


        //删除行
        function deleteRow(event, moduleFlag, rowFlag) {
            const moduleIndex = moduleList.findIndex(item => item.key == moduleFlag)
            moduleList[moduleIndex].field_data = moduleList[moduleIndex].field_data.filter(item => item.rowFlag !== rowFlag)
            moduleList[moduleIndex].htmlList = getModule(moduleFlag, moduleList[moduleIndex].field_data,
                moduleList[moduleIndex].module_name, moduleList[moduleIndex].module_type)
            initModules()
        }

        //新增字段值
        function addSelfField(e, moduleFlag) {
            const index = moduleList.findIndex(item => item.key == moduleFlag)
            console.log(index,'>>>>')
            moduleList[index].field_data.push({
                rowFlag: generateTenDigitRandomNumber(),
                ...rowDataStruct()
            })
            console.log(moduleList,moduleList[index].field_data,'>>>>')
            moduleList[index].htmlList = getModule(moduleFlag, moduleList[index].field_data, moduleList[index].module_name,
                moduleList[index].module_type)
            initModules()
        }

        //行信息改变设值
        function getRowValue(event, moduleFlag, rowFlag, field) {
            // console.log(event.target.value, event.target.checked, moduleFlag, rowFlag, moduleList)
            let moduleIndex = moduleList.findIndex(item => item.key == moduleFlag)
            let rowIndex = moduleList[moduleIndex].field_data.findIndex(item => item.rowFlag == rowFlag)
             console.log(field,'>>>>.')
            //如果是自定义配置项需要和设置联动需要重新渲染页面
            if (field === 'custom_type') {
                moduleList[moduleIndex].field_data[rowIndex][field] = event.target.value
                moduleList[moduleIndex].htmlList = getModule(moduleFlag, moduleList[moduleIndex].field_data,
                    moduleList[moduleIndex].module_name, moduleList[moduleIndex].module_type)
                initModules()
            }if(['name','short_name'].includes(field)){
              let value=event.target.value
              console.log(moduleList)
              let allFieldData=[]
              moduleList.forEach(item=>{
              if(item.field_data){
              allFieldData.push(...item.field_data)
              }})
             if(value&&'short_name'===field&&allFieldData.some((item,index)=>item[field]==value&&item.rowFlag!=rowFlag)){
             showToastr(`字段简称不能重复`)
             }
            //自定义字段 简称需要赋值给field
            if('short_name'===field&&moduleList[moduleIndex].field_data[rowIndex].is_system==2){
             moduleList[moduleIndex].field_data[rowIndex]['field'] = value
            }
              moduleList[moduleIndex].field_data[rowIndex][field] = value
            }else if(['is_modify','is_nullable'].includes(field)){
             moduleList[moduleIndex].field_data[rowIndex][field] = event.target.checked ? 2:1
            }else{
                let value = !['is_export', 'is_modify', 'is_readonly', 'is_hidden'].includes(field) ? event
                        .target.value :
                    event.target.checked ? 1 : 2
                moduleList[moduleIndex].field_data[rowIndex][field] = value
            }
         moduleList[moduleIndex].htmlList = getModule(moduleFlag, moduleList[moduleIndex].field_data,
                            moduleList[moduleIndex].module_name, moduleList[moduleIndex].module_type)
        }

        var currChangeNameModule = ''
        //更改模块名称
        function changeName(event, moduleFlag, module_name) {
            $('#nameChangeModal').modal('show')
            $("#new_module_name").val(module_name)
            currChangeNameModule = moduleFlag
        }

        //设置模块名称
        function setModuleName() {
            let val = $("#new_module_name").val()
            console.log(currChangeNameModule, val)
            let moduleIndex = moduleList.findIndex(item => item.key == currChangeNameModule)
            if(moduleList.some(item=>item.module_name===val)){
               showToastr('模块名称不能重复')
            }else{
                        moduleList[moduleIndex].module_name = val
                        moduleList[moduleIndex].htmlList = getModule(currChangeNameModule, moduleList[moduleIndex].field_data,
                            moduleList[moduleIndex].module_name, moduleList[moduleIndex].module_type)
                        $('#nameChangeModal').modal('hide')
                        initModules()
                        currChangeNameModule = ''
            }
        }


        var currChangeCustomTypeModule = ''
        var currChangeCustomTypeRowIndex = ''
        //设置
        function handleSetting(e, moduleFlag, rowFlag, custom_config) {
            $('#settingModal').modal('show')
            $('.custom_type_select').html('')
            currChangeCustomTypeModule = moduleFlag
            currChangeCustomTypeRowIndex = rowFlag
            console.log(currChangeCustomTypeModule, '>>>>')
            //有自定义下拉选项时需要回填没有则新增一个空选项
            if (custom_config != 'undefined' && custom_config && custom_config.length > 0) {
                let custom_config_list = custom_config.split(',')
                for (var i = 0; i < custom_config_list.length; i++) {
                    const flagConfig=generateTenDigitRandomNumber()
                    $('.custom_type_select').append(getSelection(custom_config_list[i],flagConfig))
                }
            } else {
                 const flagConfig=generateTenDigitRandomNumber()
                $('.custom_type_select').append(getSelection(null,flagConfig))
            }
        }

        //保存自定义配置
        function saveSetSelect() {
            let custom_config = []
            let moduleIndex = moduleList.findIndex(item => item.key == currChangeCustomTypeModule)
            console.log(moduleList, currChangeCustomTypeModule, currChangeCustomTypeRowIndex, '>>>.')
            let rowIndex = moduleList[moduleIndex].field_data.findIndex(item => item.rowFlag == currChangeCustomTypeRowIndex)
            for (let i = 0; i < $('.custom_type_select').children().length; i++) {
                custom_config.push($('.custom_type_select').children()[i].children[1].value)
            }
            if(!custom_config.some(item=>!item)){
            moduleList[moduleIndex].field_data[rowIndex].custom_config = custom_config
                        moduleList[moduleIndex].htmlList = getModule(currChangeCustomTypeModule, moduleList[moduleIndex].field_data,
                            moduleList[moduleIndex].module_name, moduleList[moduleIndex].module_type)
                        $('.custom_type_select').html('')
                        $('#settingModal').modal('hide')
                        initModules()

            }else{
                showToastr('请设置选项')
            }
        }


        //单选或者多选设置下拉选项
        function addSelection(event) {
            if ($('.custom_type_select').children().length >= 100) {
                showToastr('最多添加100个选项')
                return
            }
           const id=event.target.id+'-row'
           //新增项也要添加标识
           const flagConfig=generateTenDigitRandomNumber()
            $(`#${id}`).after(getSelection(null,flagConfig))
        }


        //移除单选或者多选设置下拉选项
        function removeSelection(event) {
            if ($('.custom_type_select').children().length === 1 || $('.custom_type_select').children().length < 1) {
                showToastr('至少保留一个选项')
                return
            }
            $(event.target).parent().remove()
        }


        //上移或者下移
        function handleMove(event, moduleFlag, rowFlag, type) {
            const moduleIndex = moduleList.findIndex(item => item.key == moduleFlag)
            const rowIndex = moduleList[moduleIndex].field_data.findIndex(item => item.rowFlag == rowFlag)
            if (type === 'up') {
                const temp = moduleList[moduleIndex].field_data[rowIndex]
                moduleList[moduleIndex].field_data[rowIndex] = moduleList[moduleIndex].field_data[rowIndex - 1]
                moduleList[moduleIndex].field_data[rowIndex - 1] = temp
            } else {
                const temp = moduleList[moduleIndex].field_data[rowIndex]
                moduleList[moduleIndex].field_data[rowIndex] = moduleList[moduleIndex].field_data[rowIndex + 1]
                moduleList[moduleIndex].field_data[rowIndex + 1] = temp
            }
            moduleList[moduleIndex].htmlList = getModule(moduleFlag, moduleList[moduleIndex].field_data, moduleList[moduleIndex]
                .module_name, moduleList[moduleIndex].module_type)
            initModules()
        }


        //获取模块字符串
        function getModule(moduleFlag, rowList, module_name, module_type) {
            const moduleStr = `<form class="table_form_self_module" id='${moduleFlag}' novalidate="" method="post">
                <table id="self_module_table" class="table table-bordered table-hover m-0">
                    <thead class="thead-themed">
                        <tr class="sub_title">
                            <th colspan="12" class="th_title">
                                <div class="title-text">
                                    <span class='${moduleFlag}+module_name'>${module_name}</span>
                                </div>
                                <div>
                                    <button onclick="changeName(event,'${moduleFlag}','${module_name}')"  type="button" data-toggle="modal" class="btn btn-primary btn-sm">更改名称</button>
                                    <button onclick="addSelfField(event,'${moduleFlag}','${module_name}')" type="button" class="btn btn-primary btn-sm">添加字段</button>
                                    <button onclick="deleteSelfModule(event,'${moduleFlag}')", type="button"
                                        class="btn btn-primary btn-sm ${module_type==2?'isShow':'isHiden'}">删除模块</button>
                                </div>
                            </th>
                        </tr>
                    <tbody style="background: #fff">
                        <tr class="form_tr title_tr" }>
                            <td>字段名称</td>
                            <td>简写</td>
                            <td>字段类型</td>
                            <td>选项</td>
                            <td>排序</td>
                            <td>导出字段</td>
                            <td>教师是否只读</td>
                            <td>学生是否只读</td>
                            <td>学生是否必填</td>
                            <td>学生是否隐藏</td>
                            <td>填写提示</td>
                        </tr>
                        ${getRow(moduleFlag,rowList)}
                      </tbody>
                    </thead>
                </table>
            </form>`
            return moduleStr
        };

        //获取行或者模块模板html字符串
        function getRow(moduleFlag, rowList) {
            const allList = rowList.map((item, index) => {
            console.log(item,'>>>>>rowList')
                return `
            <tr class="form_tr content">
                        <td>
                            <div class="form-group">
                                <input type="text" name="name" maxlength="10" id="${moduleFlag+'_'+item.rowFlag+'name'}" class="form-control form-control-sm" onblur="getRowValue(event,'${moduleFlag}',${item.rowFlag},'name')" value="${item.name}">
                            </div>
                        </td>
                        <td>
                            <div class="form-group">
                                <input type="text" name="short_name" id="${moduleFlag+'_'+item.rowFlag+'short_name'}" class="form-control form-control-sm" onblur="getRowValue(event,'${moduleFlag}',${item.rowFlag},'short_name')" value="${item.short_name}">
                            </div>
                        </td>
                        <td>
                            <div class="form_select">
                                <select class="js-hide-search form-control ${item.is_system==2?'':'isHiden'}" name='custom_type' id="${moduleFlag+'_'+item.rowFlag+'custom_type'}" onchange="getRowValue(event,'${moduleFlag}',${item.rowFlag},'custom_type')"  value='' >
                                    <option value="1" ${item.custom_type==1?'selected':""}>单行文本</option>
                                    <option value="2" ${item.custom_type==2?'selected':""}>多行文本</option>
                                    <option value="3" ${item.custom_type==3?'selected':""}>单选</option>
                                    <option value="4" ${item.custom_type==4?'selected':""}>多选</option>
                                    <option value="5" ${item.custom_type==5?'selected':""}>日期</option>
                                    <option value="6" ${item.custom_type==6?'selected':""}>单图</option>
                                </select>
                            <select class="js-hide-search form-control ${item.is_system==1?'':'isHiden'}" name='custom_type' id="${moduleFlag+'_'+item.rowFlag+'type'}"  disabled value='' >
                                 <option value="input" ${item.type=='input'?'selected':""}>单行文本</option>
                                 <option value="select_province" ${item.type=='select_province'?'selected':""}>单选</option>
                                 <option value="select" ${item.type=='select'?'selected':""}>单选</option>
                                 <option value="date_Ym" ${item.type=='date_Ym'?'selected':""}>日期</option>
                                 <option value="date_Ymd" ${item.type=='date_Ymd'?'selected':""}>日期</option>
                                 </select>
                            </div>
                        </td>
                        <td>
                            <button type="button" class="btn setting btn-primary btn-sm ${item.custom_type==3||item.custom_type==4?'':'isHiden'}" onclick="handleSetting(event,'${moduleFlag}',${item.rowFlag},'${item.custom_config}')">设置</button>
                        <span class="${item.custom_type==3||item.custom_type==4?'isHiden':''}">固定</span>
                        </td>
                        <td>
                            <button onclick="handleMove(event,'${moduleFlag}',${item.rowFlag},'up')" type="button" class="btn setting btn-primary btn-sm ${index==0?'isHiden':'isShow'}">上移</button>
                            <button onclick="handleMove(event,'${moduleFlag}',${item.rowFlag},'down')" type="button" class="btn setting btn-primary btn-sm ${index==rowList.length-1?'isHiden':'isShow'}"">下移</button>
                        </td>
                        <td>
                        <div class="custom-control custom-switch" onclick="getRowValue(event,'${moduleFlag}',${item.rowFlag},'is_export')">
                             <input type="checkbox" class="custom-control-input" name='is_export' id="${moduleFlag+'_'+item.rowFlag+'is_export'}" ${item.is_export==1?'checked':''} >
                             <label class="custom-control-label" for="${moduleFlag+'_'+item.rowFlag+'is_export'}"></label>
                        </div>
                        </td>
                        <td>
                            <div class="custom-control custom-switch" onclick="getRowValue(event,'${moduleFlag}',${item.rowFlag},'is_modify')">
                                <input type="checkbox" class="custom-control-input" name='is_modify'  id="${moduleFlag+'_'+item.rowFlag+'is_modify'}"  ${item.is_modify==2?'checked':''}>
                                <label class="custom-control-label" for="${moduleFlag+'_'+item.rowFlag+'is_modify'}"></label>
                            </div>
                        </td>
                        <td>
                            <div class="custom-control custom-switch" onclick="getRowValue(event,'${moduleFlag}',${item.rowFlag},'is_readonly')">
                                <input type="checkbox" class="custom-control-input" name='is_readonly'  id="${moduleFlag+'_'+item.rowFlag+'is_readonly'}"  ${item.is_readonly==1?'checked':''} >
                                <label class="custom-control-label" for="${moduleFlag+'_'+item.rowFlag+'is_readonly'}"></label>
                            </div>
                        </td>
                        <td>
                            <div class="custom-control custom-switch" onclick="getRowValue(event,'${moduleFlag}',${item.rowFlag},'is_nullable')">
                                <input type="checkbox" class="custom-control-input" name='is_nullable'  id="${moduleFlag+'_'+item.rowFlag+'is_nullable'}"  ${item.is_nullable==2?'checked':''}>
                                <label class="custom-control-label" for="${moduleFlag+'_'+item.rowFlag+'is_nullable'}"></label>
                            </div>
                        </td>
                        <td>
                            <div class="custom-control custom-switch" onclick="getRowValue(event,'${moduleFlag}',${item.rowFlag},'is_hidden')">
                                <input type="checkbox" class="custom-control-input" name="is_hidden" id="${moduleFlag+'_'+item.rowFlag+'is_hidden'}" ${item.is_hidden==1?'checked':''}>
                                <label class="custom-control-label" for="${moduleFlag+'_'+item.rowFlag+'is_hidden'}"></label>
                            </div>
                        </td>
                        <td class="row_last_td" >
                            <div class="form-group">
                                <input type="text" id="prompt" name="prompt" class="form-control form-control-sm" onblur="getRowValue(event,'${moduleFlag}',${item.rowFlag},'prompt')" value='${item.prompt}'>
                            </div>
                            <div class="delete_row ${item.is_system==1?'isHiden':''}" onclick="deleteRow(event,'${moduleFlag}',${item.rowFlag})">
                               <div class="delete_content"></div>
                        </div>
                        </td>
                    </tr>
`
            })
            return allList.join('')
        }

        //自定义单选多选html
        function getSelection(custom_config_item,id) {
            return `
             <div class="form-group row " id='${id}-row'>
                            <label class="col-sm-2 col-form-label" for="simpleinput">选项名称</label>
                            <input type="text" id="simpleinput" class="form-control col-sm-6" style="margin-right:20px;" value='${custom_config_item?custom_config_item:''}'>
                            <button id='${id}' onclick='addSelection(event)' type="button" class="btn btn-primary">添加</button>
                            <button onclick='removeSelection(event)' type="button" class="btn btn-primary">删除</button>
                        </div>
    `
        }



        //设置行或者模块标识
        function generateTenDigitRandomNumber() {
            // Math.random() 生成一个0到1之间的浮点数
            // 乘以9000000000，得到一个0到9000000000之间的浮点数
            // 加上1000000000，确保结果至少为1000000000
            // 使用Math.floor()向下取整，得到一个十位数
            return Math.floor(Math.random() * 9000000000) + 1000000000;
        }

        //获取行数据
        function rowDataStruct() {
            const rowData = {
                name: "",
                field: "",
                type: "",
                is_system: 2,
                custom_type: '5',
                custom_config: [],
                short_name: '',
                is_nullable: 1,
                is_readonly: 2,
                is_hidden: 2,
                is_modify: 1,
                is_export: 1,
                prompt: ''
            }
            return rowData
        }

        //提示窗体
        function showToastr(msg, title = '提示') {
            toastr.options = {
                "closeButton": true,
                "debug": false,
                "newestOnTop": true,
                "progressBar": true,
                "positionClass": "toast-top-right",
                "preventDuplicates": true,
                "onclick": null,
                "showDuration": 300,
                "hideDuration": 100,
                "timeOut": 3000,
                "extendedTimeOut": 1000,
                "showEasing": "swing",
                "hideEasing": "linear",
                "showMethod": "fadeIn",
                "hideMethod": "fadeOut"
            }
            toastr["error"](msg, title);
        }

        //提交表单
        function handleSubmit() {
        //行信息都是必填
        const required=["name",'short_name']
        let allFieldData=[]
        moduleList.forEach(item=>{
        if(item.field_data){
         allFieldData.push(...item.field_data)
         }})
         if(moduleList.some(item=>!item.module_name)){
         return showToastr(`模块名称必填`)
         }
         if(moduleList.some(item=>item.field_data&&item.field_data.length==0)){
         return showToastr(`模块字段不能为空`)
         }
         const nullIndex=allFieldData.findIndex(item=>!(item.name&&item.short_name))
         if(nullIndex!==-1){
          return showToastr(`字段名称，字段简称必填`)
         }
         const nullIndex2=allFieldData.some(item=>((item.custom_type==3||item.custom_type==4)&&(!item.custom_config||item.custom_config.length==0)))
              if(nullIndex2){
               return showToastr(`单选或多选需设置下拉选项`)
              }
            //新增模块行排序字段
            let formatList=moduleList.map((item,index)=>{
            let field_data=[]
             if(item.field_data&&item.field_data.length>0){
                 field_data=item.field_data.map((fields,fieldsIndex)=>{
                     return{
                     ...fields,
                      display:fieldsIndex,
                      custom_config:fields.custom_config?fields.custom_config:[]
                     }
                 })
             }
              return {
                 ...item,
                 module_sort:index,
                 field_data,
              }
            })
            console.log(formatList,'>>>>')
            const resultData=JSON.stringify(formatList)
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                url: '/admin/employ/student/fieldConfig?format=json&act=do',
                type : 'post',
                data : {filed_data : resultData},
                dataType: 'json',
                success: function(res) {
                    if(res.status == 1){
                        successMessage('字段设置成功');
                       setTimeout(()=>{
                        window.history.back()
                       },3000)
                    }
                    else {
                        errorMessage(res.message);
                    }
                },
                error: function() {
                    errorMessage('更新失败');
                }

            })
        }
    </script>